package com.ailk.tcm.hffw.android.utils;

import android.content.Context;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;

/**
 * 权限：<uses-permission android:name="android.permission.WAKE_LOCK"/>
 * <uses-permission android:name="android.permission.DEVICE_POWER"/>
 * @author Chris
 *
 */
public class PowerUtil {
	private Context context;

	public PowerUtil(Context context) {
		this.context = context;
	}

	WakeLock wakeLock = null;

	public void acquireWakeLock() {
		if (null == wakeLock) {
			PowerManager pm = (PowerManager) context
					.getSystemService(Context.POWER_SERVICE);
			wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
					| PowerManager.ON_AFTER_RELEASE, this.getClass().getName());
			if (null != wakeLock) {
				wakeLock.acquire();
			}
		}
	}

	// 释放设备电源锁
	public void releaseWakeLock() {
		if (null != wakeLock) {
			wakeLock.release();
			wakeLock = null;
		}
	}
}
